<template>
	<view>
		<view class="title">
			<text>表单名称</text>
			<span>名称不能为空</span>
		</view>
		<textarea @input="getTitle" class="textarea-top" placeholder="在此输入表单名称" :value="title"></textarea>
		<view>
			<view class="title-bottom">表单说明</view>
			<textarea @input="getExplain" class="textarea-bottom" placeholder="在此输入表单说明" :value="beizhu"></textarea>
		</view>
		<view class="save" @tap="Save">确定</view>
	</view>
</template>

<script>
	import api from "@/common/api.js";
	import {
		baseURL
	} from "@/common/http.js";
	export default {
		data() {
			return {
				title: '',
				beizhu: '',
				id: ''
			};
		},
		methods: {
			getTitle(e) {
				this.title = e.detail.value
			},
			getExplain(e) {
				this.beizhu = e.detail.value
			},
			Save() {
				let that = this
				let data = {
					api: 'updatec',
					table: '3',
					text: that.beizhu,
					namewenid: that.title,
					wenid: that.wenid,
					id: that.id
				}
				api.editSur(data).then(res => {
					console.log(res)
					if (res.code == 200) {
						uni.navigateTo({
							url: '../editForm/editForm?wenid=' + this.wenid
						})
					} else {
						uni.showToast({
							title: "编辑失败",
							duration: 1000,
							icon: 'none'
						})
					}
				}).catch(err => {
					console.log(err)
				})
			}
		},
		onShareAppMessage(options) {
			let shareObj = {
				success: (res) => {
					if (res.errMsg == 'shareAppMessage:ok') {
						uni.showToast({
							title: '分享成功',
							icon: 'success',
							duration: 1500
						})
					}
				},
				fail: () => {
					if (res.errMsg == 'shareAppMessage:fail cancel') {
						uni.showToast({
							title: '取消分享',
							icon: 'none',
							duration: 2000
						})
					} else if (res.errMsg == 'shareAppMessage:fail') {
						// 转发失败，其中 detail message 为详细失败信息
					}
				},
				complete: () => {
					// 转发结束之后的回调（转发成不成功都会执行）
				}
			}
		},
		onLoad(options) {
			let that = this
			let items = JSON.parse(options.item)
			this.title = items.title
			this.wenid = items.wenid
			this.id = items.id
			items.text == "添加问卷说明" ? this.beizhu = "" : this.beizhu = items.text
		}
	}
</script>

<style lang="scss">
	page {
		font-family: PingFang SC;
		font-weight: 500;
	}

	.title {
		width: 690rpx;
		margin: 80rpx auto 20rpx;

		text {
			color: #333;
			font-size: 36rpx;
			margin-right: 10rpx;
		}

		span {
			color: #E60000;
			font-size: 24rpx;
		}
	}

	.placeholder {
		font-size: 32rpx;
		color: #999;
		font-weight: normal;
	}

	.textarea-top,
	.textarea-bottom {
		padding: 20rpx;
		box-sizing: border-box;
		width: 690rpx;
		height: 200rpx;
		margin: 0 auto;
		border: 1rpx solid #999;
		border-radius: 5rpx;
		font-weight: normal;
	}

	.title-bottom {
		width: 690rpx;
		margin: 30rpx auto;
		font-size: 36rpx;
		color: #333;
	}

	.textarea-bottom {
		height: 250rpx;
	}

	.save {
		width: 690rpx;
		height: 100rpx;
		line-height: 100rpx;
		font-size: 36rpx;
		background: #209FFC;
		color: #fff;
		text-align: center;
		border-radius: 50rpx;
		margin: 100rpx auto 0;
	}
</style>
